package com.leyou.user.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import tk.mybatis.mapper.annotation.KeySql;

import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.util.Date;

/**
 * description: 用户实体类
 * @author 朱正磊
 * @date 2021-04-16 15:38:52
 */
@Data
@Table(name = "tb_user")
public class User {

    /**
     * 自增长主键，用户ID
     */
    @Id
    @KeySql(useGeneratedKeys = true)
    private Long id;

    /**
     * 用户名
     */
    @NotBlank(message = "用户名不能为空")
    @Length(min = 4, max = 32, message = "用户名长度必须在4~32位之间")
    private String username;

    /**
     * 密码
     */
    @JsonIgnore
    @NotBlank(message = "密码不能为空")
    @Length(min = 4, max = 32, message = "密码长度必须在4~32位之间")
    private String password;

    /**
     * 电话
     */
    @Pattern(regexp = "^\\d{4}-\\d{7,8}$|^\\d{11}$|^\\+86\\d{11}$|^0\\d{10,12}$|^\\d{7,8}$", message = "电话号码格式不合法")
    private String phone;

    /**
     * 创建时间
     */
    private Date created;

    /**
     * 密码的盐值
     */
    @JsonIgnore
    private String salt;

}
